// Register page module
// ====================

define(['zepto', 'sui', 'submitForm'], function($) {
  return {
    init: function(data) {
      this.batchId = data.batchId;
      this.dailyId = data.dailyId;
      this.isSignin = data.isSignin;
      this.monthlyId = data.monthlyId;
      
      this.initPage();
    },
    initPage: function() {
        var that = this;
    	$(".start-task-btn").on("click", function() {
    	  if(that.isSignin == 'true') {
    		  window.location.href = window.__CTX__.root + "/courses/" + that.monthlyId + "/batches/" + that.batchId + "/units/" + that.dailyId + "/homework";
    	  } else {
    		  that.startAction();
    	  }
      })
    },
    
    startAction: function() {
    	var that = this;
    	$.ajax({
  		  type: "POST",
  		  url: window.__CTX__.root + "/courses/" + that.monthlyId + "/batches/" + that.batchId + "/units/" + that.dailyId + "/start",
  		  success: function(res) {
  			  res = JSON.parse(res);
  			  if(res.code == 0) {
  				  window.location.href = window.__CTX__.root + "/courses/" + that.monthlyId + "/batches/" + that.batchId + "/units/" + that.dailyId + "/homework";
  			  } else {
  				  $.toast(res.message);
  			  }
  		  },
  		  failure: function() {
  			  $.toast("请求失败")
  		  }
  	  })
    }
   
  }
})